package com.hera.process.config.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.hera.base.dao.repository.BaseRepository;
import com.hera.process.form.domain.DynaformField;
import com.hera.process.form.domain.DynaformFieldPK;
import com.hera.process.form.domain.FormField;

public interface DynaformFieldDao extends BaseRepository<DynaformField,  DynaformFieldPK> {

	@Modifying
	@Transactional
	@Query("delete from DynaformField o where o.dynaformFieldPK.idDynaform = ? and o.dynaformFieldPK.idField = ?")
	public void deleteByFormField(Long idDynaform,Long idField);
	
	@Query("select o from DynaformField o where o.dynaformFieldPK.idDynaform = ? and o.field.name = ?")
	public List<DynaformField> findAllByDynaFormField(Long idDynaform,String name);

	@Query("select o from DynaformField o where o.dynaformFieldPK.idDynaform = ?")
	public List<DynaformField> findAllByDynaFormFieldByIdDynaForn(Long idDynaform);
	
	
	@Query("select o from FormField o where o.idProcess = ?1 and o.idField not in ?2")
	public List<FormField> findAllFormNoasignado(Long idProcess,List codigos);
	
	@Query("select o.dynaformFieldPK.idField from DynaformField o where o.dynaformFieldPK.idDynaform = ? and o.dynaform.idProcess=?")
	public List<Long> findAllFormSiasignadoIds(Long idDynaform,Long idProcess );
	
	@Query("select o from DynaformField o where o.dynaformFieldPK.idField = ?")
	public List<DynaformField> selectByIdFormField(Long idField);
	
	@Query("select max(o.sequence) + 1 from DynaformField o where o.dynaformFieldPK.idDynaform = ?")
	public Integer getMaxCodePerFormulario(Long idDynaform);
	
}
